package com.www.jpa.dao;

import com.www.jpa.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface UserDao extends JpaRepository<User, Long> {

    @Query("from User where id=?1")
    User getUser(int id);

    @Query(value = "select * from testJPA where id=?1", nativeQuery = true)
    User getUserBySQL(int id);

    @Modifying
    @Query("update User set name=:name,age=:age where id=:id")
    User updateUser(@Param("id") int id, @Param("name") String name, @Param("age")String age);

    @Transactional
    @Modifying
    @Query("delete from User where id=?1")
    int delUser(int id);
}
